package com.buddha.api.controller;

import com.buddha.api.common.Result;
import com.buddha.api.entity.Car;
import com.buddha.api.service.impl.ArticleServiceImpl;
import com.buddha.api.service.impl.BrandServiceImpl;
import com.buddha.api.service.impl.CarServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin(origins = {"*"})
@RestController
@RequestMapping("/client")
public class ClientController {

    @Autowired
    private BrandServiceImpl brandService;

    @Autowired
    private CarServiceImpl carService;

    @Autowired
    private ArticleServiceImpl articleService;

    @GetMapping("/hotBrand")
    public Result getHotBrand(){
        return Result.success(brandService.getPartBrand());
    }

    @GetMapping("/carRecommend")
    public Result getRecommend(){
        List<Car> cars = carService.Recommend();
        return Result.success(cars);
    }

    @GetMapping("/carSelect")
    public Result selectCar(@RequestParam String curBrand,
                            @RequestParam String lvl,
                            @RequestParam String energy,
                            @RequestParam(defaultValue = "0") Integer minPrice,
                            @RequestParam(defaultValue = "0") Integer maxPrice
    ){
        List<Car> cars = carService.carSelect(curBrand, lvl, energy, minPrice, maxPrice);
        return Result.success(cars);
    }

    @GetMapping("/hotArti")
    public Result getHotArticle(){
        return Result.success(articleService.getHotArti());
    }
}
